import { NNotificationProvider } from "naive-ui";
import type { NotificationProviderProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import type { BaseComponentType } from "../types";
import { getSlotsDom } from "../utils";

export type NotificationProviderFactoryConstructorType = {
  props?: NotificationProviderProps;
  attrs?: HTMLAttributes;
  defaultSlot?: BaseComponentType;
};

export class NotificationProviderFactory {
  private attrs: HTMLAttributes = {};
  private props: NotificationProviderProps = {};
  private defaultSlot: BaseComponentType = null;

  constructor(param?: NotificationProviderFactoryConstructorType) {
    if (param?.props) this.setProps(param.props);
    if (param?.attrs) this.setAttrs(param.attrs);
    if (param?.defaultSlot) this.setDefault(param.defaultSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: NotificationProviderProps) {
    this.props = props;
    return this;
  }
  setDefault(defaultSlot: BaseComponentType) {
    this.defaultSlot = defaultSlot;
    return this;
  }

  create() {
    return (
      <NNotificationProvider {...this.attrs} {...this.props}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot)
              : null,
        }}
      </NNotificationProvider>
    );
  }
}
